package com.hippy.erya.modular.util;

import com.hippy.erya.sys.core.constant.cache.Cache;

import java.text.MessageFormat;


public class LabelUtils {


    public static String drawContent(String source, String label) {
        String prefix = MessageFormat.format(Cache.LABEL_PREFIX, label);
        int prefixIndex;
        if ((prefixIndex = source.indexOf(prefix)) == -1) {
            return source;
        }
        String suffix = MessageFormat.format(Cache.LABEL_SUFFIX, label);
        int suffixIndex;
        if ((suffixIndex = source.indexOf(suffix)) == -1) {
            return source;
        }
        String[] split = source.substring(prefixIndex + prefix.length(), suffixIndex).split(Cache.LINE_FEED_SIGN);
        StringBuilder builder = new StringBuilder();
        for (String txt : split) {
            builder.append(Cache.LINE_FEED_SIGN).append(txt);
        }
        return builder.toString().substring(Cache.LINE_FEED_SIGN.length() + 1);
    }


}
